<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:c="http://java.sun.com/jsp/jstl/core">
    <h:head>
        <title>Currency Converter</title>
    </h:head>
    <h:body>
        <h1>Currency Converter</h1>
        <h:form>
            <h:commandLink id="link" action="goToAdminPage">
                <h:outputText value="Edit currencies and exchange rates"/>
            </h:commandLink>
        </h:form>

        <h:form>
            <p>
                <h3 style="color: red">
                    <h:outputText value="#{converter.exception.message}" rendered="#{!converter.success}" />
                </h3>
            </p>

            <table>
                <tr>
                    <td>
                        <h:outputLabel for="fromList" value="From:" />
                    </td>
                    <td>
                        <h:selectOneMenu id="fromList" value="#{converter.fromCurrencyStr}">
                            <f:selectItems value="#{converter.currencyList}" />
                        </h:selectOneMenu> 
                    </td>
                </tr>

                <tr>
                    <td>
                        <h:outputLabel for="toList" value="To:" />
                    </td>
                    <td>
                        <h:selectOneMenu id="toList" value="#{converter.toCurrencyStr}">
                            <f:selectItems value="#{converter.currencyList}" />
                        </h:selectOneMenu> 
                    </td>
                </tr>

                <tr>
                    <td>
                        <h:outputLabel for="amount" value="Amount:"/>
                    </td>
                    <td>
                        <h:inputText id="amount" value="#{converter.amount}" validatorMessage="Amount should be more than 0!">                            
                            <!--<f:validateRegex pattern="+?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?"/>-->
                            <f:validateLongRange minimum="0" />
                        </h:inputText>
                    </td>
                </tr>

                <tr>
                    <td>
                        <h:commandButton value="Convert" action="#{converter.convert}"/>
                    </td>
                </tr>

                <tr>
                    <td>
                        <h:outputLabel for="result" value="Result:"/>
                    </td>
                    <td>
                        <h:outputText id="result" value="#{converter.result}" />
                    </td>
                </tr>
            </table>
        </h:form>        
    </h:body>
</html>

